$(function() {
	$("#addform").validate({
		submitHandler : function(form) {// 必须写在验证前面，否则无法ajax提交
			ly.ajaxSubmit(form, {// 验证新增是否成功
				type : "post",
				dataType : "json",
				success : function(data) {
					if (data == "success") {
						layer.msg('添加成功!');
						grid.loadData();
						layer.close(pageii);
					} else {
						layer.alert(data);
					}
				}
			});
		},
		rules : {
			"residentFormMap.userName" : {
				required : true,
				minlength : 2,
				maxlength : 5
			},
			"residentFormMap.phone" : {
				required : true,
				isMobile : true
			},
			"residentFormMap.password": {
				required : true,
				minlength : 6,
				maxlength : 18
			},
			"residentFormMap.userAddr" : {
				required : true
			}
		},
		messages : {
			"residentFormMap.userName" : {
				required : "请输入居民姓名",
				minlength : "姓名长度不能少于2个字符",
				maxlength : "姓名长度不能大于5个字符"
			},
			"residentFormMap.phone" : {
				required : "请输入手机号码",
				isMobile : "手机号码格式不正确"
			},
			"residentFormMap.password": {
				required : "请输入登陆密码",
				minlength : "密码长度不能少于6个字符",
				maxlength  :"密码长度不能大于18个字符"
			},
			"residentFormMap.userAddr" : {
				required : "请输入地址"
			}
		},
		errorPlacement : function(error, element) {// 自定义提示错误位置
			$(".l_err").css('display', 'block');
			// element.css('border','3px solid #FFCCCC');
			$(".l_err").html(error.html());
		},
		success : function(label) {// 验证通过后
			$(".l_err").css('display', 'none');
		}
	});
});
